#include "alt.h"
#include <string>
using namespace std;

regex_base* alt::copy() const
{
     alt* p = new alt;

     for(size_t i = 0;i<options.size();i++)
     {
          p->options.push_back(options.at(i)->copy());
     }
     return p;
}

alt::~alt()
{
     for(size_t i = 0;i<options.size();i++)
     {
          delete options.at(i);
     }
}

match_result alt::match(const std::string& s) const
{
     for(size_t i = 0; i<options.size();i++)
     {
          match_result data = options.at(i)->match(s);
          if(data.get_matched())
          {
               return data;
          }
     }

     return match_result(false,0);
}


//end 'alt'; begin 'range'

regex_base* range::copy() const
{
     range* p = new range(low,high);

     return p;
}

match_result range::match(const string& x) const
{
     if(x.length()>0)
     {
          if(x.at(0)>=low && x.at(0)<=high)
          {
               return match_result(true,1);
          }
          else
          {
               return match_result(false,0);
          }
     }
     else
     {
          return match_result(false,0);
     }
}
